<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../../vue.js"></script>
    <style>
        li {
            list-style: none;
        }
        
        h2,
        p {
            margin: 0;
        }
        
        #box {
            margin: 30px auto;
            width: 300px;
        }
        
        #user,
        #message {
            box-sizing: border-box;
            width: 300px;
            border: 1px solid #000;
            padding: 10px;
            height: 100px;
            resize: none;
            display: block;
        }
        
        #user {
            padding: 0 10px;
            height: 30px;
            margin-bottom: 10px;
        }
        
        #btn {
            display: block;
            margin: 10px auto;
            width: 60%;
            height: 40px;
        }
        
        #list {
            border-top: 1px solid #000;
            padding: 10px 0 0;
            margin: 0;
            list-style: none;
        }
        
        #list li {
            position: relative;
            font: 14px/30px "宋体";
            border-bottom: 1px solid #000;
            padding: 0 15px;
            overflow: hidden;
        }
        
        .clos {
            position: absolute;
            right: 5px;
            top: 10px;
        }
        
        .clos2 {
            position: absolute;
            right: 5px;
            top: 30px;
        }
        /* .replay{
    position:absolute;
    right: 5px;
    top: 35px;
} */
        
        .mask {
            width: 100vw;
            height: 100vh;
            background: black;
            opacity: 0.3;
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }
        
        .comfirm {
            width: 200px;
            height: 120px;
            background: white;
            text-align: center;
            position: absolute;
            left: 50%;
            top: 30%;
            border-radius: 5px;
            transform: translate(-50%, -50%);
            overflow: hidden;
            display: none;
        }
        
        .comfirm button {
            /* position: absolute; */
            /* right: 10px; */
            float: right;
            margin-top: 20px;
            margin-right: 10px;
        }
        /* .replay {
            display: none;
        } */
    </style>
</head>

<body>
    <div id="box">
        <input type="text" id="user" placeholder="小明" v-model="myuser" />
        <textarea id="message" placeholder="我就是传说中的无敌小明" v-model="myMes"></textarea>
        <button id="btn" @click="btns">提交留言</button>
        <ul id="list">
            <li v-for="(item,index) in arr">
                <h2 class="user">{{item.name}}说:</h2>
                <p>{{item.message}}</p>
                <p v-for="(val,i) in item.replayData">{{val}}</p>
                <div class="replay" v-if="item.isif">
                    <input type="text" v-model="item.myQued" />

                    <button class="sure" @click="qD(index)">确定</button>
                    <button class="cancel" @click="dele(index)">取消</button>
                </div>
                <a href="javascript:;" class="clos" @click="del(index)">删除</a>
                <a href="javascript:;" class="clos2" @click="huif(index)">回复</a>
            </li>
        </ul>
    </div>
    <script>
        var arr = [{
            name: "小张",
            message: "1111",
            replayData: [],
        }, {
            name: "小张",
            message: "2222",
            replayData: [],
        }, {
            name: "小张",
            message: "333",
            replayData: [],
        }, ];

        arr.forEach((item) => {
            item.isif = false;
            item.myQued = "";
        });
        new Vue({
            el: "#box",
            data: {
                myuser: "",
                myMes: "",
                arr: [],
            },
            methods: {
                btns() {
                    // console.log(this.myuser);

                    this.arr.push({
                        name: this.myuser,
                        message: this.myMes,
                        replayData: [],
                        isif: false,
                        myqued: "",
                    });

                    this.myuser = "";
                    this.myMes = "";
                },
                del(index) {
                    // console.log("del", index);
                    this.arr.splice(index, 1);
                },
                huif(index) {
                    this.arr[index].isif = true;
                },

                qD(index) {
                    // console.log(this.myqued);
                    this.arr[index].replayData.push(this.arr[index].myQued);
                    this.arr[index].isif = false;
                    this.myQued = "";
                },
                dele(index) {
                    this.arr[index].isif = false;
                },
            },
        });
    </script>
</body>

</html>